
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/mechanics/advanced.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:38 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Potential Issues/Advanced Topics/Future Features in Physics/Mechanics &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="advanced.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="References for Physics/Mechanics" href="reference.html" />
    <link rel="prev" title="Multi Degree of Freedom Holonomic System" href="examples/multi_degree_freedom_holonomic_system.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="reference.html" title="References for Physics/Mechanics"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="examples/multi_degree_freedom_holonomic_system.html" title="Multi Degree of Freedom Holonomic System"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Classical Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Potential Issues/Advanced Topics/Future Features in Physics/Mechanics</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="potential-issues-advanced-topics-future-features-in-physics-mechanics">
<h1>Potential Issues/Advanced Topics/Future Features in Physics/Mechanics<a class="headerlink" href="#potential-issues-advanced-topics-future-features-in-physics-mechanics" title="Permalink to this headline">¶</a></h1>
<p>This document will describe some of the more advanced functionality that this
module offers but which is not part of the “official” interface. Here, some of
the features that will be implemented in the future will also be covered, along
with unanswered questions about proper functionality. Also, common problems
will be discussed, along with some solutions.</p>
<section id="common-issues">
<h2>Common Issues<a class="headerlink" href="#common-issues" title="Permalink to this headline">¶</a></h2>
<p>Here issues with numerically integrating code, choice of <code class="docutils literal notranslate"><span class="pre">dynamicsymbols</span></code> for
coordinate and speed representation, printing, differentiating, and
substitution will occur.</p>
<section id="numerically-integrating-code">
<h3>Numerically Integrating Code<a class="headerlink" href="#numerically-integrating-code" title="Permalink to this headline">¶</a></h3>
<p>See Future Features: Code Output</p>
</section>
<section id="differentiating">
<h3>Differentiating<a class="headerlink" href="#differentiating" title="Permalink to this headline">¶</a></h3>
<p>Differentiation of very large expressions can take some time in SymPy; it is
possible for large expressions to take minutes for the derivative to be
evaluated. This will most commonly come up in linearization.</p>
</section>
<section id="choice-of-coordinates-and-speeds">
<h3>Choice of Coordinates and Speeds<a class="headerlink" href="#choice-of-coordinates-and-speeds" title="Permalink to this headline">¶</a></h3>
<p>The Kane object is set up with the assumption that the generalized speeds are
not the same symbol as the time derivatives of the generalized coordinates.
This isn’t to say that they can’t be the same, just that they have to have a
different symbol. If you did this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;</span> <span class="n">KM</span><span class="o">.</span><span class="n">coords</span><span class="p">([</span><span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">q3</span><span class="p">])</span>
<span class="o">&gt;&gt;</span> <span class="n">KM</span><span class="o">.</span><span class="n">speeds</span><span class="p">([</span><span class="n">q1d</span><span class="p">,</span> <span class="n">q2d</span><span class="p">,</span> <span class="n">q3d</span><span class="p">])</span>
</pre></div>
</div>
<p>Your code would not work. Currently, kinematic differential equations are
required to be provided. It is at this point that we hope the user will
discover they should not attempt the behavior shown in the code above.</p>
<p>This behavior might not be true for other methods of forming the equations of
motion though.</p>
</section>
<section id="printing">
<h3>Printing<a class="headerlink" href="#printing" title="Permalink to this headline">¶</a></h3>
<p>The default printing options are to use sorting for <code class="docutils literal notranslate"><span class="pre">Vector</span></code> and <code class="docutils literal notranslate"><span class="pre">Dyad</span></code>
measure numbers, and have unsorted output from the <code class="docutils literal notranslate"><span class="pre">mprint</span></code>, <code class="docutils literal notranslate"><span class="pre">mpprint</span></code>, and
<code class="docutils literal notranslate"><span class="pre">mlatex</span></code> functions. If you are printing something large, please use one of
those functions, as the sorting can increase printing time from seconds to
minutes.</p>
</section>
<section id="substitution">
<h3>Substitution<a class="headerlink" href="#substitution" title="Permalink to this headline">¶</a></h3>
<p>There are two common issues with substitution in mechanics:</p>
<ul>
<li><p>When subbing in expressions for <code class="docutils literal notranslate"><span class="pre">dynamicsymbols</span></code>, sympy’s normal <code class="docutils literal notranslate"><span class="pre">subs</span></code>
will substitute in for derivatives of the dynamic symbol as well:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.mechanics</span> <span class="kn">import</span> <span class="n">dynamicsymbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span> <span class="o">+</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sub_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span> <span class="mi">1</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">sub_dict</span><span class="p">)</span>
<span class="go">Derivative(1, t) + 1</span>
</pre></div>
</div>
<p>In this case, <code class="docutils literal notranslate"><span class="pre">x</span></code> was replaced with 1 inside the <code class="docutils literal notranslate"><span class="pre">Derivative</span></code> as well,
which is undesired.</p>
</li>
<li><p>Substitution into large expressions can be slow.</p></li>
</ul>
<p>If your substitution is simple (direct replacement of expressions with other
expressions, such as when evaluating at an operating point) it is recommended
to use the provided <code class="docutils literal notranslate"><span class="pre">msubs</span></code> function, as it is significantly faster, and
handles the derivative issue appropriately:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.mechanics</span> <span class="kn">import</span> <span class="n">msubs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">msubs</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">sub_dict</span><span class="p">)</span>
<span class="go">Derivative(x(t), t) + 1</span>
</pre></div>
</div>
</section>
<section id="linearization">
<h3>Linearization<a class="headerlink" href="#linearization" title="Permalink to this headline">¶</a></h3>
<p>Currently, the linearization methods don’t support cases where there are
non-coordinate, non-speed dynamic symbols outside of the “dynamic equations”.
It also does not support cases where time derivatives of these types of dynamic
symbols show up. This means if you have kinematic differential equations which
have a non-coordinate, non-speed dynamic symbol, it will not work. It also
means if you have defined a system parameter (say a length or distance or mass)
as a dynamic symbol, its time derivative is likely to show up in the dynamic
equations, and this will prevent linearization.</p>
</section>
<section id="acceleration-of-points">
<h3>Acceleration of Points<a class="headerlink" href="#acceleration-of-points" title="Permalink to this headline">¶</a></h3>
<p>At a minimum, points need to have their velocities defined, as the acceleration
can be calculated by taking the time derivative of the velocity in the same
frame. If the 1 point or 2 point theorems were used to compute the velocity,
the time derivative of the velocity expression will most likely be more complex
than if you were to use the acceleration level 1 point and 2 point theorems.
Using the acceleration level methods can result in shorted expressions at this
point, which will result in shorter expressions later (such as when forming
Kane’s equations).</p>
</section>
</section>
<section id="advanced-interfaces">
<h2>Advanced Interfaces<a class="headerlink" href="#advanced-interfaces" title="Permalink to this headline">¶</a></h2>
<section id="advanced-functionality">
<h3>Advanced Functionality<a class="headerlink" href="#advanced-functionality" title="Permalink to this headline">¶</a></h3>
<p>Remember that the <code class="docutils literal notranslate"><span class="pre">Kane</span></code> object supports bodies which have time-varying
masses and inertias, although this functionality isn’t completely compatible
with the linearization method.</p>
<p>Operators were discussed earlier as a potential way to do mathematical
operations on <code class="docutils literal notranslate"><span class="pre">Vector</span></code> and <code class="docutils literal notranslate"><span class="pre">Dyad</span></code> objects. The majority of the code in this
module is actually coded with them, as it can (subjectively) result in cleaner,
shorter, more readable code. If using this interface in your code, remember to
take care and use parentheses; the default order of operations in Python
results in addition occurring before some of the vector products, so use
parentheses liberally.</p>
</section>
</section>
<section id="future-features">
<h2>Future Features<a class="headerlink" href="#future-features" title="Permalink to this headline">¶</a></h2>
<p>This will cover the planned features to be added to this submodule.</p>
<section id="code-output">
<h3>Code Output<a class="headerlink" href="#code-output" title="Permalink to this headline">¶</a></h3>
<p>A function for generating code output for numerical integration is the highest
priority feature to implement next. There are a number of considerations here.</p>
<p>Code output for C (using the GSL libraries), Fortran 90 (using LSODA), MATLAB,
and SciPy is the goal. Things to be considered include: use of <code class="docutils literal notranslate"><span class="pre">cse</span></code> on large
expressions for MATLAB and SciPy, which are interpretive. It is currently unclear
whether compiled languages will benefit from common subexpression elimination,
especially considering that it is a common part of compiler optimization, and
there can be a significant time penalty when calling <code class="docutils literal notranslate"><span class="pre">cse</span></code>.</p>
<p>Care needs to be taken when constructing the strings for these expressions, as
well as handling of input parameters, and other dynamic symbols. How to deal
with output quantities when integrating also needs to be decided, with the
potential for multiple options being considered.</p>
</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Potential Issues/Advanced Topics/Future Features in Physics/Mechanics</a><ul>
<li><a class="reference internal" href="#common-issues">Common Issues</a><ul>
<li><a class="reference internal" href="#numerically-integrating-code">Numerically Integrating Code</a></li>
<li><a class="reference internal" href="#differentiating">Differentiating</a></li>
<li><a class="reference internal" href="#choice-of-coordinates-and-speeds">Choice of Coordinates and Speeds</a></li>
<li><a class="reference internal" href="#printing">Printing</a></li>
<li><a class="reference internal" href="#substitution">Substitution</a></li>
<li><a class="reference internal" href="#linearization">Linearization</a></li>
<li><a class="reference internal" href="#acceleration-of-points">Acceleration of Points</a></li>
</ul>
</li>
<li><a class="reference internal" href="#advanced-interfaces">Advanced Interfaces</a><ul>
<li><a class="reference internal" href="#advanced-functionality">Advanced Functionality</a></li>
</ul>
</li>
<li><a class="reference internal" href="#future-features">Future Features</a><ul>
<li><a class="reference internal" href="#code-output">Code Output</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="examples/multi_degree_freedom_holonomic_system.html"
                        title="previous chapter">Multi Degree of Freedom Holonomic System</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="reference.html"
                        title="next chapter">References for Physics/Mechanics</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/mechanics/advanced.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="reference.html" title="References for Physics/Mechanics"
             >next</a> |</li>
        <li class="right" >
          <a href="examples/multi_degree_freedom_holonomic_system.html" title="Multi Degree of Freedom Holonomic System"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Classical Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Potential Issues/Advanced Topics/Future Features in Physics/Mechanics</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/mechanics/advanced.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:38 GMT -->
</html>